<?php

namespace Hanson\MyVbot\Handlers\Type;

use Hanson\Vbot\Message\Emoticon;
use Hanson\Vbot\Message\Image;
use Hanson\Vbot\Message\Text;
use Hanson\Vbot\Message\Video;
use Hanson\Vbot\Message\Voice;
use Hanson\Vbot\Message\File;
use Illuminate\Support\Collection;
use Hanson\MyVbot\Html\Pdfcrowd;

class ShareType
{
    public static function messageHandler(Collection $message)
    {
        if ($message['type'] === 'share') {
            if('' != $message['url']){
                try {
                    $res = Pdfcrowd::html_to_pdf($message['url']);
                }catch (\Exception $e){
                    Text::send($message['from']['UserName'], $e->getMessage());
                    return;
                }

                if(false !== $res){
                    try {
                        File::send($message['from']['UserName'], "/tmp/" . $res);
                        echo "/tmp/" . $res . "\n";
                    }catch (\Exception $e){
                        Text::send($message['from']['UserName'], $e->getMessage());
                    }
                }else{
                    Text::send($message['from']['UserName'], ' 抓取失败了！');
                }
            }
        }
    }
}
